package com.example.seckill.dao;

import com.example.seckill.entity.SeckillOrder;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface SeckillOrderMapper {
    
    @Insert("INSERT INTO seckill_order(user_id, goods_id, order_status) VALUES(#{userId}, #{goodsId}, #{orderStatus})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(SeckillOrder order);
    
    @Select("SELECT * FROM seckill_order WHERE id = #{id}")
    SeckillOrder selectById(Long id);
    
    /**
     * 根据用户ID和商品ID查询订单
     */
    @Select("SELECT * FROM seckill_order WHERE user_id = #{userId} AND goods_id = #{goodsId} LIMIT 1")
    SeckillOrder selectByUserIdAndGoodsId(@Param("userId") Long userId, @Param("goodsId") Long goodsId);

    @Select("SELECT * FROM seckill_order WHERE user_id = #{userId}")
    List<SeckillOrder> selectByUserId(@Param("userId") Long userId);
} 